#include "gameselect.h"
#include<QIcon>
#include<QPushButton>
#include"gamehall.h"
#include<QSound>
#include<QPainter>
#include<QPixmap>
#include"gameroom.h"
#include<QTextEdit>
#include<QFile>
#include<QTextStream>
GameSelect::GameSelect(QWidget *parent) : QWidget(parent)
{
        //跳转界面的设置
        this->setFixedSize(1000,800);
        this->setWindowTitle("游戏关卡选择");
        this->setWindowIcon(QIcon(":image/snake.png"));
        QPushButton*back=new QPushButton(this);
        back->move(950,750 );
        back->setIcon(QIcon(":image/return.png"));
        back->setFixedSize(50,50);
        connect(back,&QPushButton::clicked,[=]{
            this->close();
            GameHall*hall=new GameHall;
            hall->show();
            QSound::play(":image/return.wav");
        });

        //第二个界面的跳转以及按钮设置
        Gameroom*room=new Gameroom;
        QPushButton*select1=new QPushButton(this);
        select1->setText("简单模式");
        select1->move(420,160);
         QFont font("华文行楷",24);
        select1->setFont(font);
        select1->setStyleSheet("QPushButton { border: 2px solid black; border-radius: 10px; color:white;}");
        connect(select1,&QPushButton::clicked,[=]{
            room->setGeometry(this->geometry());
            this->close();
            room->show();
              QSound::play(":image/clicked.wav");
              room->settimeout(300);
        });

        QPushButton*select2=new QPushButton(this);
        select2->setText("正常模式");
        QFont font2("华文行楷",24);
       select2->setFont(font);
       select2->move(420,320);
       select2->setStyleSheet("QPushButton { border: 2px solid black; border-radius: 10px; color:white;}");
       connect(select2,&QPushButton::clicked,[=]{
           room->setGeometry(this->geometry());
           this->close();
           room->show();
            QSound::play(":image/clicked.wav");
            room->settimeout(100);
       });


       QPushButton*select3=new QPushButton(this);
       select3->setText("困难模式");
       QFont font3("华文行楷",24);
      select3->setFont(font);
      select3->move(420,480);
      select3->setStyleSheet("QPushButton { border: 2px solid black; border-radius: 10px; color:white;}");
      connect(select3,&QPushButton::clicked,[=]{
          room->setGeometry(this->geometry());
          this->close();
          room->show();
           QSound::play(":image/clicked.wav");
           room->settimeout(50);
      });

      QPushButton*select4=new QPushButton(this);
      select4->setText("历史成绩");
      QFont font4("华文行楷",24);
     select4->setFont(font);
     select4->move(420,640);
     select4->setStyleSheet("QPushButton { border: 2px solid black; border-radius: 10px;color:white; }");

     //历史战绩实现
     connect(select4,&QPushButton::clicked,[=](){
         QWidget*widget=new QWidget;
         widget->setWindowTitle("历史战绩");
         widget->setFixedSize(500,300);
         widget->setWindowIcon(QIcon(":image/snake.png"));

         QTextEdit*edit=new QTextEdit(widget);
         edit->setFixedSize(500,300);
         QFile file("C:/Users/12443/Desktop/snake/snake/score.txt");
         file.open(QIODevice::ReadOnly);
         QTextStream text(&file);
         int score=text.readLine().toInt();
         edit->append("您的上一次得分为：");
         edit->append(QString::number(score));
         edit->setFont(font);
        widget->show();
     });

}

void GameSelect::paintEvent(QPaintEvent *event)
{
    (void)event;
    QPainter painter(this);
    QPixmap pixmap(":image/background2.png");
    painter.drawPixmap(0,0,1000,800,pixmap);


}
